<template>
  <div class="table-box">
    <div class="table-search">
      <div class="btn-box">
        <el-button type="primary" @click="onQuery">查询</el-button>
        <el-button type="primary" plain @click="onExport">导出</el-button>
      </div>
    </div>
    <div class="card content-box">
      <div class="table">
        <el-table :data="tableData" border v-loading="loading">
          <el-table-column prop="name" label="项目名称" align="center" />
          <el-table-column prop="code" label="项目代码" align="center" />
        </el-table>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, reactive } from "vue";

import { projectApi } from "@/api/system/system";
import { exportToExcel } from "@/utils/utils";
const tableData = ref([]);
const loading = ref(false);
// 参数
const param = () => {
  return {};
};

// 获取表格数据
const getTbaleData = async () => {
  loading.value = true;
  try {
    const res = await projectApi(param());
    loading.value = false;
    tableData.value = res.data;
  } catch (error) {
    loading.value = false;
  }
};

// 查询
const onQuery = async () => {
  getTbaleData();
};
// 导出
const onExport = async () => {
  const data = Object.assign(param(), { export: 1 });
  const res = await projectApi(data);

  let head = {
    name: "项目名称",
    code: "项目code",
  };exportToExcel(res.data, head, "项目列表");
  
};

onMounted(() => {
  getTbaleData();
});
</script>
